'use strict';

const db = uniCloud.database();

exports.main = async (event, context) => {
	
	let body = event;
	if (event.body != undefined) {
		body = JSON.parse(event.body)
	}
	const validTestId=['1','2','3']

    const testId = body.testId
	if (!testId) {
	    return {
	        code: -1,
	        message: '缺少 testId 参数'
	    };
	}

	
	if(!validTestId.includes(testId)){
		return{
			code:-3,
			message:"无效的testId"
		}
	}

    try {
        const collection = db.collection('mind_test_questions');
        const res = await collection.where({ testId }).get();
        
        return {
            code: 0,
            message: '获取成功',
            data: res.data
        };
    } catch (error) {
        return {
            code: -4,
            message: '数据库查询失败',
            error: error.message
        };
    }
};
